package coreModelTests;

import static org.junit.Assert.*;

import hitExceptions.InvalidDataException;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import coreModel.*;

public class SupplyTest {
static List<Supply> list;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	list = new ArrayList<Supply>();
		
		for(int x=0;x<20;x++)
		{
			float size = x;
			Unit units[]=Unit.values();
			int unit = x%units.length;
			Supply tmp = new Supply(x,units[unit]);
			list.add(tmp);
		}
	}

	@Before
	public void setUp() throws Exception
	{
	}

	@Test
	public void testGetSupplySize()
	{
		int x=0;
		for(Supply p: list)
		{
			assertTrue(p.getSupplySize()==x);
			x++;
		}
	}

	@Test
	public void testSetSupplySize() throws InvalidDataException
	{
		int x=20;
		for(Supply p: list)
		{
			p.setSupplySize(x);
			assertTrue(p.getSupplySize()==x);
			x--;
		}
		x=-1;
		
		for(Supply p: list)
		{
			boolean failure=true;
			try
			{
				p.setSupplySize(x);
				
			} 
			catch (InvalidDataException e)
			{
				failure=false;
			}
			x--;
			if(failure)
				fail();
		}
	}

	@Test
	public void testGetSupplyUnit()
	{
		int x=0;
		Unit units[]=Unit.values();

		for(Supply p: list)
		{
			int unit = x%units.length;
			assertEquals(p.getSupplyUnit(),units[unit]);
			x++;
		}
	}

	@Test
	public void testSetSupplyUnit()
	{
		for(Supply p: list)
		{
			p.setSupplyUnit(Unit.COUNT);
			assertEquals(p.getSupplyUnit(),Unit.COUNT);
			p.setSupplyUnit(Unit.GRAMS);
			assertEquals(p.getSupplyUnit(),Unit.GRAMS);
			
		}
	}

}
